package com.wukaige.goods.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wukaige.goods.entity.Goods;
import com.wukaige.goods.service.IGoodsService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wukaige
 * @since 2021-05-05
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    IGoodsService goodsService;

    @RequestMapping("getgoods")
    @GlobalTransactional
    public IPage getgoods(Page page, Goods goods) {
        IPage pageinfo = goodsService.getgoods(page, goods);
        return pageinfo;
    }

    @GetMapping("/getgoodsbygid")
    public Goods getgoodsbygid(@RequestParam(value = "gid") Integer gid) {
        System.out.println(gid);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("gid", gid);
        return goodsService.getOne(wrapper);
    }

    @RequestMapping("/updatebygid")
    public boolean updatebygid(@RequestParam(value = "gid") Integer gid, @RequestParam(value = "goodsum") Integer goodsum,@RequestParam(value = "invent") Integer invent) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("gid", gid);
        Goods one = goodsService.getOne(wrapper);
        one.setGoodsum(goodsum);
        one.setInvent(invent);
        boolean b = goodsService.updateById(one);
        return b;
    }

}
